package cn.wolfcode.controller;

import cn.wolfcode.domain.Department;
import cn.wolfcode.domain.Permission;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IPermissionService;
import cn.wolfcode.service.IRoleService;
import cn.wolfcode.util.RequiredPermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    private IPermissionService permissionService;
    @Autowired
    private IRoleService roleService;
    @RequestMapping("/list")
    @RequiredPermission(name="权限页面",expression ="permission:list")
    public String list(@ModelAttribute("qo") QueryObject qo, Model model){
        PageInfo<Permission> pageInfo = permissionService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "/permission/list";
    }
    @RequestMapping("/reload")
    @RequiredPermission(name="权限加载",expression ="permission:reload")
    public String reload(){
        //加载数据库中所有的权限
        permissionService.reload();
        return "redirect:/permission/list";
    }


}
